//
//  RxTableViewController2.swift
//  RXSwiftTest
//
//  Created by ZhangBo on 2019/4/14.
//  Copyright © 2019 ZhangBo. All rights reserved.
//

import UIKit

//作者：八级大狂风AM
//链接：https://www.jianshu.com/p/f61a5a988590

class RxTableViewController2: UITableViewController {
    let reuserId: String = "cell"//重用标识
    let vcNames = [
        "JSViewController01",
        "JSViewController02",
        "JSViewController03",
        "JSViewController04",
        "JSViewController05",
        "RxViewController6",
        "RxViewController7",
        "RxViewController8",
        "RxViewController9",
        "RxViewController10",
        "RxViewController1",
        "RxViewController2",
        "RxViewController3",
        "RxViewController4",
        "RxViewController5",
        "RxViewController6",
        "RxViewController7",
        "RxViewController8",
        "RxViewController9",
        "RxViewController20",
        "JSViewController21",
        "JSViewController22",
        "JSViewController23",
        "RxViewController4",
        "RxViewController5",
        "RxViewController6",
        "JSViewController27",
        "RxViewController8",
        "RxViewController9",
        "RxViewController30",
        "JSViewController31",
        "JSViewController32",
        "RxViewController3",
        "RxViewController4",
        "RxViewController5",
        "JSViewController36",
        "RxViewController7",
        "RxViewController8",
        "RxViewController9",
        "RxViewController40",
        "RxViewController1",
        "JSViewController42",
        "JSViewController43",
        "JSViewController44",
        "JSViewController45",
        "JSViewController46",
        "RxViewController7",
        "JSViewController48",
        "JSViewController49",
        "JSViewController50",
        "RxViewController1",
        "RxViewController2",
        "RxViewController3",
        "RxViewController4",
        "RxViewController5",
        "JSViewController56",
        "JSViewController57",
        "RxViewController8",
        "RxViewController9",
        "RxViewController60",
        "RxViewController1",
        "RxViewController2",
        "RxViewController3",
        "RxViewController4"
    ]
    let items = [
        "1 基本介绍、安装配置",
        "2 响应式编程与传统式编程的比较样例",
        "3 Observable介绍、创建可观察序列",
        "4 Observable订阅、事件监听、订阅销毁",
        "5 观察者1： AnyObserver、Binder",
        "6 观察者2： 自定义可绑定属性",
        "7 Subjects、Variables",
        "8 变换操作符：buffer、map、flatMap、scan等",
        "9 过滤操作符：filter、take、skip等",
        "10 条件和布尔操作符：amb、takeWhile、skipWhile等",
        "11 结合操作符：startWith、merge、zip等",
        "12 算数&聚合操作符：toArray、reduce、concat",
        "13 连接操作符：connect、publish、replay、multicast",
        "14 其他操作符：delay、materialize、timeout等",
        "15 错误处理",
        "16 调试操作",
        "17 特征序列1：Single、Completable、Maybe",
        "18 特征序列2：Driver",
        "19 特征序列3：ControlProperty、 ControlEvent",
        "20 调度器、subscribeOn、observeOn",
        "21 UI控件扩展1：UILabel",
        "22 UI控件扩展2：UITextField、UITextView",
        "23 UI控件扩展3：UIButton、UIBarButtonItem",
        "24 UI控件扩展4：UISwitch、UISegmentedControl",
        "25 UI控件扩展5：UIActivityIndicatorView、UIApplication",
        "26 UI控件扩展6：UISlider、UIStepper",
        "27 双向绑定：<->",
        "28 UI控件扩展7：UIGestureRecognizer",
        "29 UI控件扩展8：UIDatePicker",
        "30 UITableView的使用1：基本用法",
        "31 UITableView的使用2：RxDataSources",
        "32 UITableView的使用3：刷新表格数据",
        "33 UITableView的使用4：表格数据的搜索过滤",
        "34 UITableView的使用5：可编辑表格",
        "35 UITableView的使用6：不同类型的单元格混用",
        "36 UITableView的使用7：样式修改",
        "37 UICollectionView的使用1：基本用法",
        "38 UICollectionView的使用2：RxDataSources",
        "39 UICollectionView的使用3：刷新集合数据",
        "40 UICollectionView的使用4：样式修改",
        "41 UIPickerView的使用",
        "42 [unowned self] 与 [weak self]",
        "43 URLSession的使用1：请求数据",
        "44 URLSession的使用2：结果处理、模型转换",
        "45 结合RxAlamofire使用1：数据请求",
        "46 结合RxAlamofire使用2：结果处理、模型转换",
        "47 结合RxAlamofire使用3：文件上传",
        "48 结合RxAlamofire使用4：文件下载",
        "49 结合Moya使用1：数据请求",
        "50 结合Moya使用2：结果处理、模型转换",
        "51 MVVM架构演示1：基本介绍、与MVC比较",
        "52 MVVM架构演示2：使用Observable样例",
        "53 MVVM架构演示3：使用Driver样例",
        "54 一个用户注册样例1：基本功能实现",
        "55 一个用户注册样例2：显示网络请求活动指示器",
        "56 结合MJRefresh使用1：下拉刷新",
        "57 结合MJRefresh使用2：上拉加载、以及上下拉组合",
        "58 DelegateProxy样例1：获取地理定位信息",
        "59 DelegateProxy样例2：图片选择功能",
        "60 DelegateProxy样例3：应用生命周期的状态变化",
        "61 sendMessage和methodInvoked的区别",
        "62 订阅UITableViewCell里的按钮点击事件",
        "63 通知NotificationCenter的使用",
        "64 键值观察KVO的使用"
    ]

    override func viewDidLoad() {
        super.viewDidLoad()
        title = "Swift - RxSwift的使用详解"
        //创建一个重用的单元格
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: reuserId)
    }

    // MARK: - Table view data source

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.items.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: reuserId, for: indexPath)
        let model = self.items[indexPath.row]
        cell.textLabel?.text = model
        if vcNames[indexPath.row].contains("JSViewController") {
            cell.textLabel?.textColor = .blue
        }else {
            cell.textLabel?.textColor = .black
        }
        return cell
    }

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let row = indexPath.row
        guard let vc = getClass(stringName: (self.vcNames[row])) else {
            return
        }
        self.navigationController?.pushViewController(vc, animated: true)
    }

}

